package com.jhhc.Config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
@MapperScan( value = {"com.jhhc.BDMS.Data.Dao","com.jhhc.BDMS.System.Dao","com.jhhc.BDMS.File.Dao"},sqlSessionFactoryRef = "sqlSessionFactory8")
public class BDMSConfig {

    @Autowired
    @Qualifier("bdmsDataSource")
    private DataSource bdms;

    @Bean(name = "sqlSessionFactory8")
    @Primary
    public SqlSessionFactory sqlSessionFactory8() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(bdms);
        return sqlSessionFactoryBean.getObject();
    }

    @Bean
    @Primary
    public SqlSessionTemplate sqlSessionTemplate8() throws Exception {
        SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory8());
        return sqlSessionTemplate;
    }
}
